﻿using Platformer_Example.Controller.Terrain;
using System;

namespace Platformer_Example.Controller.Character.Behavior
{
    public class BaseAiBehavior : BaseBehavior
    {
        public override void UpdateJumpState(System.TimeSpan gameTime)
        {
            Character.ChangeDirectionFromInput();
            Character.ChangeWalkSpeedFromInput();

            Character.ApplyGravity(gameTime);

            Character.ApplyMovementX(gameTime);
            var collisionResult = Character.ApplyMovementY(gameTime, true);
            if (collisionResult == BaseTerrain.TerrainType.Floor)
                Character.ChangeState(BaseInputCharacter.State.Idle);
            else if (collisionResult == BaseTerrain.TerrainType.Ceiling)
            {
                Character.ResetGravityY();
            }

            else if (Character.GravityVector.Y + Character.PushbackVector.Y > 0)
                Character.ChangeState(BaseInputCharacter.State.Fall);

            Character.ApplyWarps();
        }

        private bool _isServer = true;
        protected void TakeActionIfServer(Action action)
        {
            if (_isServer)
            {
                action();
            }
        }
    }
}